# 作者： 李泉志
# 2025年01月08日18时27分秒
# 2947029073@qq.com
class HouseItem:
    def __init__(self, name, area):
        """
        初始化家具
        :param name: 家具名字
        :param area: 占地面积
        """
        self.name = name
        self.area = area

    def __str__(self):
        return "[%s] 占地 %.2f" % (self.name, self.area)


class House:
    def __init__(self, house_type, area):
        """
        初始化房子
        :param house_type:
        :param area:
        """
        self.house_type = house_type
        self.area = area
        # 剩余面积
        self.free_area = area
        # 家具名称列表
        self.item_list = []

    def __str__(self):
        return ("户型：%s\n总面积：%.2f[剩余：%.2f]\n家具：%s"
                % (self.house_type, self.area, self.free_area, self.item_list))

    def add_item(self, item: HouseItem):  # ':'后是注解
        print("要添加 %s" % item)
        if item.area <= self.free_area:
            self.item_list.append(item.name)
            self.free_area -= item.area
        else:
            print("剩余空间不足！")


if __name__ == '__main__':
    bed = HouseItem("床", 4)
    chest = HouseItem("衣柜", 2)
    table = HouseItem("桌子", 1.5)
    print(bed)
    print(chest)
    print(table)
    house = House("三室两厅", 100)
    house.add_item(bed)
    house.add_item(chest)
    house.add_item(table)
    print(house)